package com.atguigu.gmall.cart.api;

import com.atguigu.gmall.cart.entity.CartItem;
import com.atguigu.gmall.cart.service.CartService;
import com.atguigu.gmall.cart.vo.AddCartSuccessVo;
import com.atguigu.gmall.common.auth.UserAuthInfo;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.common.utils.UserAuthUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 思考问题1：购物项应该包含商品的哪些数据？取决于在购物车列表页面要展示哪些数据
 * 思考问题2：添加商品到购物车中该接口应该返回什么数据？  AddCartSuccessVo
 */
@RestController
@RequestMapping(value = "/api/inner/cart")
@Slf4j
public class CartApiController {

    @Autowired
    private CartService cartService ;

    @GetMapping(value = "/addCart")
    public Result<AddCartSuccessVo> addCart(@RequestParam(value = "skuId") Long skuId , @RequestParam(value = "skuNum") Integer skuNum ) {
        AddCartSuccessVo addCartSuccessVo = cartService.addCart(skuId , skuNum) ;
        return Result.ok(addCartSuccessVo) ;
    }

    @DeleteMapping(value = "/deleteCheckedCart")
    public Result deleteCheckedCart(){
        cartService.deleteCheckedCart() ;
        return Result.ok() ;
    }

    @GetMapping(value = "/findByUserId")
    public Result<List<CartItem>> findByUserId() {
        List<CartItem> cartItemList = cartService.findByUserId() ;
        return Result.build(cartItemList , ResultCodeEnum.SUCCESS) ;
    }

}
